<?php
require_once('connection.php');
$cid = $_SESSION['SESS_CID'];
$getMyOrder = "SELECT bo.recName, bo.recAddress, bo.recPhoneNo, bo.deliverDate, bo.orderDate, bo.oid, bo.status
        FROM bookingorder bo
		WHERE bo.cid = '$cid'
		ORDER BY bo.orderDate ASC";
$myOrders = mysql_query($getMyOrder);
function getnum($oid){
	$sql_getnum = "SELECT num
					FROM contains
					WHERE contains.oid = '$oid'";
	$num_result = mysql_query($sql_getnum);
	return mysql_fetch_array($num_result)[0];
}
function getQuantity($oid){
	$sql_getFromContains = "SELECT contains.fname, contains.fsize
							FROM contains
							WHERE contains.oid = '$oid'";
	$resultIncontains = mysql_query($sql_getFromContains);
	if (!$resultIncontains){
		die('Error: ' . mysql_error());
		return false;
	}
	$f = mysql_fetch_array($resultIncontains);
	$fname = $f['fname'];
	$fsize = $f['fsize'];
    $sql_available = "SELECT f.quantity 
					  FROM flowers f
					  WHERE f.fname = '$fname' AND f.size = '$fsize'";
	$favaliableNumResult = mysql_query($sql_available);
	if (!$favaliableNumResult){
		die('Error: ' . mysql_error());
		return false;
	}
	$row_num = mysql_fetch_row($favaliableNumResult);
	$avaliable_num = $row_num[1];
	return $avaliable_num;
}
function getFlowerName($oid){
	$sql_getFromContains = "SELECT contains.fname, contains.fsize
							FROM contains
							WHERE contains.oid = '$oid'";
	$resultIncontains = mysql_query($sql_getFromContains);
	if (!$resultIncontains){
		die('Error: ' . mysql_error());
		return false;
	}
	$f = mysql_fetch_array($resultIncontains);
	$fname = $f['fname'];
	return $fname;
}
function getFlowerSize($oid){
	$sql_getFromContains = "SELECT contains.fname, contains.fsize
							FROM contains
							WHERE contains.oid = '$oid'";
	$resultIncontains = mysql_query($sql_getFromContains);
	if (!$resultIncontains){
		die('Error: ' . mysql_error());
		return false;
	}
	$f = mysql_fetch_array($resultIncontains);
	$fname = $f['fsize'];
	return $fname;
}
function getFlowerPicture($oid){
	/*$fname = getFlowerName($oid);
	$fsize = getFlowerSize($oid);*/
	$sql_getFromContains = "SELECT f.picture
							FROM flowers f, contains c 
							WHERE c.oid = '$oid' AND c.fname = f.fname AND c.fsize = f.size";
	/*$sql_getFromContains = "SELECT f.picture
							FROM flowers f
							WHERE f.fname = $fname AND f.size = $fsize";*/
	$resultIncontains = mysql_query($sql_getFromContains);
	if (!$resultIncontains){
		die('Error: ' . mysql_error());
		return false;
	}
	$f = mysql_fetch_row($resultIncontains);
	$fpicture = $f[0];
	return $fpicture;
}
?>